import pandas as pd 
import numpy as np 
import sys
import os
import csv

def calcCorr():
	dirname = sys.argv[1]
	dirs = os.listdir(dirname)
	length = len(dirs)
	f = open("result.csv","wb")
	csvF = csv.writer(f)
	for i in range(length):
		for j in range(length):
			if i != j:
				dataA = np.loadtxt(dirname+dirs[i])
				dataB = np.loadtxt(dirname+dirs[j])
				d0 = []
				d1 = []
				for k in range(len(dataA)):
					for item in dataA[k]:
						d0.append(item)
				for p in range(len(dataB)):
					for item in dataB[p]:
						d1.append(item)
				d = pd.DataFrame({0:d0,1:d1})
				print(d.corr[0][1])
				csvF.writerows(dirs[i]+","+dirs[j]+","+str(d.corr[0][1]))
	f.close()

if __name__=='__main__':
	calcCorr()